class WritsController < ApplicationController
  # GET /writs
  # GET /writs.xml
  def index
    if params[:user_id]
      @writs = Writ.all(:conditions => {:user_id => @current_user})
    else
      @writs = Writ.all
    end

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @writs }
    end
  end

  # GET /writs/1
  # GET /writs/1.xml
  def show
    @writ = Writ.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @writ }
    end
  end

  # GET /writs/new
  # GET /writs/new.xml
  def new
    @writ = Writ.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @writ }
    end
  end

  # GET /writs/1/edit
  def edit
    @writ = Writ.find(params[:id])
  end

  # POST /writs
  # POST /writs.xml
  def create
    @writ = Writ.new(params[:writ])

    respond_to do |format|
      if @writ.save
        flash[:notice] = 'Writ was successfully created.'
        format.html { redirect_to(@writ) }
        format.xml  { render :xml => @writ, :status => :created, :location => @writ }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @writ.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /writs/1
  # PUT /writs/1.xml
  def update
    @writ = Writ.find(params[:id])

    respond_to do |format|
      if @writ.update_attributes(params[:writ])
        flash[:notice] = 'Writ was successfully updated.'
        format.html { redirect_to(@writ) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @writ.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /writs/1
  # DELETE /writs/1.xml
  def destroy
    @writ = Writ.find(params[:id])
    @writ.destroy

    respond_to do |format|
      format.html { redirect_to(writs_url) }
      format.xml  { head :ok }
    end
  end
end
